export default class Utils {
  static createElement<K extends keyof HTMLElementTagNameMap>(
    tagName: K,
    options?: { className?: string; id?: string; text?: string; style?: string }
  ): HTMLElementTagNameMap[K] {
    const element = document.createElement(tagName);

    if (options) {
      if (options.className) {
        element.className = options.className;
      }
      if (options.id) {
        element.id = options.id;
      }
      if (options.text) {
        element.innerText = options.text;
      }
      if (options.style) {
        element.style.cssText = options.style;
      }
    }
    return element;
  }

  static installMetaMask() {
    if (typeof window.ethereum !== "undefined") {
      return true;
    } else {
      const div = Utils.createElement("div", {
        style:
          "width:500px; height: 200px; background-color: #fff; border-radius: 5px; box-shadow: 0 0 10px rgba(0,0,0,0.5); position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 9999;",
      });
      const p = Utils.createElement("p", {
        text: "Please install MetaMask to use this website",
        style: "text-align: center; margin-top: 50px;",
      });
      const a = Utils.createElement("a", {
        text: "Install MetaMask",
      });

      return false;
    }
  }
}
